//
//  YTProfileViewModel.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/4/28.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTProfileViewModel.h"
#import "YTProfileModel.h"
#import "YTUserProfileServices.h"

@interface YTProfileViewModel ()

@property (strong, readwrite, nonatomic) RACCommand *loadUserInfoCommand;

@end

@implementation YTProfileViewModel

- (void)initialize {
    [super initialize];
    _loadUserInfoCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
        return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
            [[YTUserProfileServices loadUserInfo] subscribeNext:^(NSDictionary *response) {
                if ([response[@"resultCode"] integerValue] == 1000) {
                    YTProfileModel *model = [YTProfileModel yy_modelWithJSON:response[@"responseData"]];
                    [YTUtilityManager manager].userModel = model;
                    [subscriber sendNext:model];
                    [subscriber sendCompleted];
                }
            } error:^(NSError *error) {
                
            }];
            return nil;
        }];
    }];
}

@end
